package com.salt.modules.log.model.data;

import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.DateFormat;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;

import java.io.Serializable;
import java.util.List;

/**
 * @Description
 * @Author salt
 * @Date 2023/4/14
 * @Version 1.0.1
 */
@Data
@Document(indexName = "operation_record", type = "_doc", createIndex = true)
public class OperationRecord implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @Field(index = true, store = true, type = FieldType.Keyword)
    private Long id;

    @Field(index = true, store = true, type = FieldType.Text, analyzer = "ik_smart")
    private String service;  // 服务名

    @Field(index = true, store = true, type = FieldType.Text, analyzer = "ik_smart")
    private String moduleName;   // 模块名 (因module是前端关键字，改为moduleName)

    @Field(index = true, store = true, type = FieldType.Keyword)
    private String operation;  // 操作

    @Field(index = true, store = true, type = FieldType.Keyword)
    private String requestMethod;  // 请求方式

    @Field(index = true, store = true, type = FieldType.Keyword)
    private String operRealName;  // 操作人姓名

    @Field(index = true, store = true, type = FieldType.Keyword)
    private String operUserId;  // 操作人ID

    @Field(index = true, store = true, type = FieldType.Keyword)
    private String userName; // 用户名

    @Field(index = true, store = true, type = FieldType.Keyword)
    private String operUrl;  // 操作的url

    @Field(index = true, store = true, type = FieldType.Keyword)
    private String operIp;   // 操作的iP

    @Field(index = false, type = FieldType.Text)
    private List<String> params;  // 请求参数

    @Field(index = false, store = true, type = FieldType.Text)
    private Object result; // 返回的数据

    @Field(index = true, store = true, type = FieldType.Date, format = DateFormat.custom, pattern = "yyyy-MM-dd HH:mm:ss")
    private String operTime;   // 操作时间

    @Field(index = false, store = true, type = FieldType.Long)
    private Long exeTime; // 耗时

    @Field(index = false, store = true, type = FieldType.Text)
    private String description;  // 描述

    @Field(index = true, store = true, type = FieldType.Integer)
    private Integer status;  // 操作状态（0正常 1异常）

    @Field(index = false, store = true, type = FieldType.Text)
    private String errorMsg;  // 错误消息


}
